import time

# 方法1
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.switch_to import SwitchTo

# 引入wait和EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException

wd = webdriver.Chrome(service=Service(".\chromedriver_win136.exe"))

wd.get("https://swtesting-class-demo.koyeb.app/elements/")
# wd.get("http://127.0.0.1:5000/elements/")
try:
    ele = (
        WebDriverWait(wd, 4).until(
            EC.element_to_be_clickable(
                (By.CSS_SELECTOR, ".accordion > .accordion-item:nth-child(1)")
            )
        )
    ).click()
    print("目标出现，继续执行")
except TimeoutException as e:
    print("目标元素未出现")
